use dta/SMDLevel.dta, clear

**************  PUTTING PARTIES INTO OTHER CATEGORY ******************

foreach var in run1 run2 {
replace `var'_oth=`var'_t+`var'_kir+`var'_oth
replace `var'_oth=1 if `var'_oth>1
}
drop *_t *_kir

************** CREATING FINAL ROUND VARIABLES ************************

gen SECOND=0
replace SECOND=1 if votes2_TOTAL!=0  

foreach party in s nsa nkp v a v_a h fv h_fv l oth {
gen votesF_`party'=votes1_`party'
replace votesF_`party'=votes2_`party' if SECOND==1
gen runF_`party'=run1_`party'
replace runF_`party'=run2_`party' if SECOND==1
gen vsF_`party'=vs1_`party'
replace vsF_`party'=vs2_`party' if SECOND==1
}


*************** CREATING FRACTION OF SMDs CONTESTED BY PARTY *********

collapse run1* runF*, by(year)

*foreach var in run1 runF {

*	foreach party in s nsa nkp v a v_a h fv h_fv l oth {
*	tw (scatter `var'_`party' year if year<1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) ///*
*	(scatter `var'_`party' year if year>1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) , ///
*	xtitle("") ytitle("") title(`party') xscale(range(1909(3)1927)) xlabel(1909(3)1927)  ///
*	plotregion(lcolor(white) ilcolor(white)) graphregion(color(white)) scheme(s1mono) legend(off)
*	graph save figures/gph/`party'.gph, replace
*	}	

*cd figures/gph/
*graph combine s.gph nsa.gph nkp.gph v.gph a.gph v_a.gph h.gph fv.gph h_fv.gph l.gph oth.gph, ycommon plotregion(lcolor(white) ilcolor(white)) graphregion(color(white)) scheme(s1mono) cols(3)
*graph export ../`var'.pdf, replace
*cd ../../
*}


*foreach var in run1 runF {
foreach var in run1 {

	tw (scatter `var'_s year if year<1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) ///
	(scatter `var'_s year if year>1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) , ///
	xtitle("") ytitle("") title(Labor Party (DNA)) xscale(range(1909(3)1927)) xlabel(1909(3)1927)  ///
	plotregion(lcolor(white) ilcolor(white)) graphregion(color(white)) scheme(s1mono) legend(off)
	graph save figures/gph/s.gph, replace
		
		tw (scatter `var'_nsa year if year<1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) ///
	(scatter `var'_nsa year if year>1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) , ///
	xtitle("") ytitle("") title(Soc. Dem. Labor (NSA)) xscale(range(1909(3)1927)) xlabel(1909(3)1927)  ///
	plotregion(lcolor(white) ilcolor(white)) graphregion(color(white)) scheme(s1mono) legend(off)
	graph save figures/gph/nsa.gph, replace
		
		tw (scatter `var'_nkp year if year<1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) ///
	(scatter `var'_nkp year if year>1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) , ///
	xtitle("") ytitle("") title(Communists (NKP)) xscale(range(1909(3)1927)) xlabel(1909(3)1927)  ///
	plotregion(lcolor(white) ilcolor(white)) graphregion(color(white)) scheme(s1mono) legend(off)
	graph save figures/gph/nkp.gph, replace
	
		tw (scatter `var'_v year if year<1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) ///
	(scatter `var'_v year if year>1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) , ///
	xtitle("") ytitle("") title(Liberals (V)) xscale(range(1909(3)1927)) xlabel(1909(3)1927)  ///
	plotregion(lcolor(white) ilcolor(white)) graphregion(color(white)) scheme(s1mono) legend(off)
	graph save figures/gph/v.gph, replace
	
		tw (scatter `var'_a year if year<1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) ///
	(scatter `var'_a year if year>1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) , ///
	xtitle("") ytitle("") title(Labor Democrats (A)) xscale(range(1909(3)1927)) xlabel(1909(3)1927)  ///
	plotregion(lcolor(white) ilcolor(white)) graphregion(color(white)) scheme(s1mono) legend(off)
	graph save figures/gph/a.gph, replace
		
		tw (scatter `var'_v_a year if year<1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) ///
	(scatter `var'_v_a year if year>1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) , ///
	xtitle("") ytitle("") title(V & A) xscale(range(1909(3)1927)) xlabel(1909(3)1927)  ///
	plotregion(lcolor(white) ilcolor(white)) graphregion(color(white)) scheme(s1mono) legend(off)
	graph save figures/gph/v_a.gph, replace

		tw (scatter `var'_h year if year<1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) ///
	(scatter `var'_h year if year>1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) , ///
	xtitle("") ytitle("") title(Conservatives (H)) xscale(range(1909(3)1927)) xlabel(1909(3)1927)  ///
	plotregion(lcolor(white) ilcolor(white)) graphregion(color(white)) scheme(s1mono) legend(off)
	graph save figures/gph/h.gph, replace
	
		tw (scatter `var'_fv year if year<1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) ///
	(scatter `var'_fv year if year>1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) , ///
	xtitle("") ytitle("") title(Progressive Liberals (FV)) xscale(range(1909(3)1927)) xlabel(1909(3)1927)  ///
	plotregion(lcolor(white) ilcolor(white)) graphregion(color(white)) scheme(s1mono) legend(off)
	graph save figures/gph/fv.gph, replace
	
		tw (scatter `var'_h_fv year if year<1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) ///
	(scatter `var'_h_fv year if year>1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) , ///
	xtitle("") ytitle("") title(H & FV) xscale(range(1909(3)1927)) xlabel(1909(3)1927)  ///
	plotregion(lcolor(white) ilcolor(white)) graphregion(color(white)) scheme(s1mono) legend(off)
	graph save figures/gph/h_fv.gph, replace
	
		tw (scatter `var'_l year if year<1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) ///
	(scatter `var'_l year if year>1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) , ///
	xtitle("") ytitle("") title(Farmers Party (SP)) xscale(range(1909(3)1927)) xlabel(1909(3)1927)  ///
	plotregion(lcolor(white) ilcolor(white)) graphregion(color(white)) scheme(s1mono) legend(off)
	graph save figures/gph/l.gph, replace
	
	
			tw (scatter `var'_oth year if year<1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) ///
	(scatter `var'_oth year if year>1920, connect(l) lpattern(dash) msymbol(circle) mcolor(black) mlcolor(black)) , ///
	xtitle("") ytitle("") title(Other) xscale(range(1909(3)1927)) xlabel(1909(3)1927)  ///
	plotregion(lcolor(white) ilcolor(white)) graphregion(color(white)) scheme(s1mono) legend(off)
	graph save figures/gph/oth.gph, replace

	

cd figures/gph/
graph combine s.gph nsa.gph nkp.gph v.gph a.gph v_a.gph h.gph fv.gph h_fv.gph l.gph oth.gph, ycommon plotregion(lcolor(white) ilcolor(white)) graphregion(color(white)) scheme(s1mono) cols(3)
graph export ../FigureA3.pdf, replace
cd ../../
}


